package com.keepalive_kotlin.activity

import android.os.Bundle
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import com.keepalive_kotlin.R

/**
 * 1像素保活Activity
 * 用于在锁屏时显示一个1像素的透明Activity，防止应用被系统杀死
 */
class OnePixelActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        // 设置Activity为1像素大小并置顶
        val window: Window = window
        window.setGravity(Gravity.START or Gravity.TOP)
        val attributes: WindowManager.LayoutParams = window.attributes
        attributes.x = 0
        attributes.y = 0
        attributes.height = 1
        attributes.width = 1
        window.attributes = attributes
        
        // 设置为透明
        window.setBackgroundDrawableResource(android.R.color.transparent)
        
        setContentView(R.layout.activity_one_pixel)
    }

    override fun onResume() {
        super.onResume()
        // 如果屏幕已解锁，则关闭此Activity
        finish()
    }
}